package zheezes.protocol.impl.wt.meta;

import java.util.Arrays;

import zheezes.util.AbstractSerial;
import zheezes.util.ByteUtil;


public class WtMtAddr extends AbstractSerial {
	public static final int SIZE = 5;
	private byte[] addr;

	public WtMtAddr() {
	}

	public WtMtAddr(String s) {
		addr = ByteUtil.stoa(s.toCharArray(), 0, SIZE * 2);
	}
	
	public String toString() {
		return new String(ByteUtil.atos(addr, "%02X"));
	}

	@Override
	public int getBytes(byte[] buf, int offset) {
		if (addr != null) {
			System.arraycopy(addr, 0, buf, offset, addr.length);
		} else {
			Arrays.fill(buf, offset, offset + SIZE, (byte) 0xFF);
		}
		return size();
	}

	@Override
	public int setBytes(byte[] buf, int offset, int max) {
		if (addr == null || addr.length < SIZE) {
			addr = new byte[SIZE];
		}
		System.arraycopy(buf, offset, addr, 0, addr.length);
		return size();
	}

	@Override
	public int size() {
		return SIZE;
	}
}
